<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "" "">
<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:w="http://www.apusic.com/jsf/widget" xmlns:layout="http://www.apusic.com/jsf/layout"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:ajax="http://www.apusic.com/jsf/ajax"
	renderKitId="AJAX">
	<w:head cache="false">
		<w:stylesheet src="/css/kmp4.css" type="text/css"></w:stylesheet>
	</w:head>
	<w:page title="请选择">
		<layout:borderLayout fitToBody="true" border="false" fit="true" margins="0 0 0 0">
			<layout:panel region="north" border="false" height="30"
				style="background-color: #DFDFDF; vertical-align: middle">
				<layout:panelGrid columns="2">
					<layout:cell style="height:30px;">
						<h:outputLabel value="快速搜索" for="searchImage"></h:outputLabel>
						<h:graphicImage url="/images/quicksearch.png" id="searchImage"></h:graphicImage>
					</layout:cell>
					<layout:cell style="height:30px;">
						<w:textField id="ps_txt" jsvar="ps_txt_jsvar" onfocus="javascript:expandTree();"
							onkeyup="javascript:searchTree(ps_txt_jsvar.getValue());"></w:textField>
					</layout:cell>
				</layout:panelGrid>
			</layout:panel>
			<layout:panel region="center" border="false" height="250" autoScroll="true">
				<w:tree id="ps_selectTree" jsvar="ps_selectTree_jsvar" expandAll="false" loadAllNodes="true"
					rootVisible="false" autoScroll="true" />
			</layout:panel>
			<layout:panel border="true" region="south" height="60">
				<div style="height: 30px; vertical-align: middle;">
				<h:outputLabel value="已选择："></h:outputLabel> <h:outputText id="selectedText"></h:outputText> <h:outputText
					id="selectedId" style="display:none;"></h:outputText>
				</div>
				<div
					style="height: 30px; vertical-align: middle; background-color: #DFDFDF; text-align: center;">
				<w:form>
					<layout:panelGrid columns="2" style="vertical-align: middle" align="center">
						<layout:cell style="height:30px;" align="right">
							<w:button label="确定" id="savesss" image="/images/save.gif" onclick="javascript:saveValue();"
								alwaysSubmit="false" immediate="true" />
						</layout:cell>
						<layout:cell style="height:30px;">
							<w:button value="取消" image="/images/cancel.gif" onclick="window.close()" immediate="true"
								alwaysSubmit="false" />
						</layout:cell>
					</layout:panelGrid>
				</w:form>
				</div>
			</layout:panel>
		</layout:borderLayout>
	</w:page>
	<script>
	//<![CDATA[
	var hiddenPkgs = [];
	var filter=null;
	var initPara= window.dialogArguments;
	var parentWindow  = initPara[0];
	var idJsvar=initPara[1];
	var nameJsvar=initPara[2];
	var selectedText=document.getElementById('selectedText');
	var selectedId=document.getElementById('selectedId');
	if(nameJsvar){
		if(selectedText)
			selectedText.innerHTML=nameJsvar.getValue();
	}
	Ext.onReady(function (){
		filter = new Ext.tree.TreeFilter(ps_selectTree_jsvar, {
		clearBlank: true,
		autoClear: true
		});
		ps_selectTree_jsvar.on('dblclick',function(node){
			//alert(node.attributes.expanded);
			if(node.attributes.expanded&&node!=ps_selectTree_jsvar.root){
				if(idJsvar){
					//var idInput=eval('window.parent.'+idJsvar);
					//alert(idJsvar);
					idJsvar.setValue(node.attributes.hrefTarget);
				}
				if(nameJsvar){
					//var nameInput=eval('window.opener.'+nameJsvar);
					//alert(nameJsvar);
					nameJsvar.setValue(node.text);
				}
				window.close();
			}
		});
		ps_selectTree_jsvar.on('click',function(node){
			if(node.attributes.expanded&&node!=ps_selectTree_jsvar.root){
				if(selectedText){
					selectedText.innerHTML=node.text;
				}
				if(selectedId){
					selectedId.innerHTML=node.attributes.hrefTarget;
				}
			}
		});
	});
	function expandTree(){
		ps_selectTree_jsvar.expandAll();
	}
	function searchTree(text){
			//alert(text);
			//Ext.each(hiddenPkgs, function(n){
			//	n.ui.show();
			//});
			//ps_selectTree_jsvar.expandAll();
			if(!text){
				filter.clear();
				return;
			}
			var re = new RegExp(text, 'i');
			filter.filterBy(function(n){
				//alert('text:'+n.text);
				//alert('expanded:'+n.attributes.expanded);
				//alert('reg:'+re.test(n.text));
				//alert(n.isLeaf());
				return !n.attributes.expanded||re.test(n.text);
			});
		}
	function saveValue(){
		if(idJsvar){
			if(selectedId)
				idJsvar.setValue(selectedId.innerHTML);
		}
		if(nameJsvar){
			if(selectedText)
				nameJsvar.setValue(selectedText.innerHTML);
		}
		window.close()
	}
	//]]></script>
</f:view>